package java学习;

/**
 * **************
 * 项目名称: 蓝桥杯 <br/>
 * 文件名称:  <br/>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br/>
 * 文件创建：刘世锦 <br/>
 * 创建时间: 2022/4/3 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
public class RunnableTest {

    public static void main(String[] args) throws InterruptedException {
//        Dog1 dog = new Dog1();
//        Thread thread = new Thread(dog);
//        thread.start();
//        dd dd = new dd();
//        Thread thread1 = new Thread(dd);
//        thread1.start();

        joinThread joinThread = new joinThread();
        joinThread.start();

        for (int i = 0; i <20 ; i++) {
            Thread.sleep(1000);
            System.out.println((i+1)+"Hi"+Thread.currentThread().getName());

            if (i==4){
                joinThread.join(5000);
            }
        }
    }
}
class Animal{ }
class Dog1 extends Animal implements Runnable{
    @Override
    public void run() {
        int t = 1;
        while (t<=10){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t+"哈哈"+Thread.currentThread().getName());
            t++;
        }
    }

}

class dd implements Runnable{

    @Override
    public void run() {
        int t = 1;
        while (t <=5){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t+"h1"+Thread.currentThread().getName());
            t++;
        }
    }
}

class joinThread extends Thread {

    @Override
    public void run() {
        int t = 1;
        while (t <=20){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t+"hello"+Thread.currentThread().getName());
            t++;
        }
    }
}